package com.flowable.controller;

import com.flowable.service.MyService;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 长沙先飞信息科技有限公司<br>
 * Created with IntelliJ IDEA.<br>
 * Date:2024/6/19<br>
 * Time:15:05<br>
 * 功能描述：<br>
 *
 * @author huang hou chun
 * @since JDK 1.8 <br>
 * Copyright (c) 2023 www.csxfrj.com System Incorporated All Rights Reserved.
 */

@RestController
public class MyRestController {

    @Resource
    private MyService myService;

    @PostMapping("/process")
    public void startProcessInstance() {
        myService.startProcess();
    }

    @GetMapping(value = "/tasks", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<TaskRepresentation> getTasks(@RequestParam String assignee) {
        return myService.getTasks(assignee)
                .stream()
                .map(task -> new TaskRepresentation(task.getId(), task.getName()))
                .collect(Collectors.toList());
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static final class TaskRepresentation {
        private String id;
        private String name;
    }
}
